package com.topvision.common.page;

import com.github.pagehelper.PageInfo;
import org.springframework.data.domain.Page;

import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author shengwm
 * @version V0.0.1
 * @Title: PageUtils
 * @Package com.topvision.common.page
 * @Description: TODO
 * @date 2017/5/31
 */
public class PageUtils {
    public static Map<String, Object> generatePaginationHashMap(Page<?> page) throws URISyntaxException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("totalElements", page.getTotalElements());
        map.put("totalPages", page.getTotalPages());
        map.put("last", page.isLast());
        map.put("first", page.isFirst());
        map.put("numberOfElements", page.getNumberOfElements());
        // map.put("sort", page.getSort());
        map.put("size", page.getSize());
        map.put("number", page.getNumber());
        return map;
    }

    public static Map<String, Object> generatePaginationHashMap(PageInfo<?> page) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("totalElements", page.getTotal());
        map.put("totalPages", page.getPages());
        map.put("last", page.isIsLastPage());
        map.put("first", page.isIsFirstPage());
        map.put("size", page.getSize());
        map.put("number", page.getPageNum());
        return map;
    }
}
